package com.helmlabs.grouper.webapp.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.helmlabs.grouper.accounts.model.UserProfile;
import com.helmlabs.grouper.accounts.service.AccountManager;
import com.helmlabs.grouper.accounts.service.AccountManagerFactory;

@Controller
@RequestMapping({"/join/category.html","/join/profile.html","/join/edit.html"})
public class JoinManagementController {
	
	private final AccountManager accountManager = AccountManagerFactory.getAccountManager();
	
	@SuppressWarnings("unchecked")
	@RequestMapping(method=RequestMethod.GET, value="/join/category.html")
	public ModelAndView prepareEditUser(@RequestParam("userid") Long userid){
		ModelAndView model = new ModelAndView("join/categoryForm");
		return model;
	}

	@SuppressWarnings("unchecked")
	@RequestMapping(method=RequestMethod.POST, value="/join/category.html")
	public String prepareEditUser(@RequestParam("userid") Long userid, @RequestParam("type") String type){
		return "redirect:/join/edit.html?type=" + type + "&userid=" + userid;
	}

	
	@SuppressWarnings("unchecked")
	@RequestMapping(method=RequestMethod.GET, value="/join/profile.html")
	public ModelAndView prepareEditUser(@RequestParam("type") String type){
		ModelAndView model = new ModelAndView("join/memberForm");
		model.addObject("profile", new UserProfile());
		model.addObject("countries", COUNTRIES);
		return model;
	}

	@SuppressWarnings("unchecked")
	@RequestMapping(method=RequestMethod.GET, value="/join/edit.html")
	public ModelAndView prepareEditProfile(@RequestParam("userid") String userid, @RequestParam("type") String type){
		ModelAndView model = new ModelAndView("join/memberForm");
		model.addObject("profile", accountManager.getUserProfile(new Long(userid)));
		model.addObject("countries", COUNTRIES);
		return model;
	}

	
	public static final String[] COUNTRIES = {
		"Afghanistan","Albania","Algeria","Andorra","Antigua and Barbuda",
		"Argentina","Armenia","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh",
		"Barbados","Belarus","Belgium","Belize","Benin","Bhutan","Bolivia","Bosnia and Herzegovina","Botswana",
		"Brazil","Brunei","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Canada","Cape Verde",

		"Central African Republic",
		"Republic",
		"Chad",
		"Chile",
		"China",
		"Colombia",
		"Comoros",
		"Congo",
		"Costa Rica",
		"C&ocirc;te d'Ivoire",

		"Croatia",
		"Cuba",
		"Cyprus",
		"Czech Republic",
		"Denmark",
		"Djibouti",
		"Dominica",
		"Dominican Republic",
		"East Timor",

		"Ecuador",
		"Egypt",
		"El Salvador",
		"Equatorial Guinea",
		"Eritrea",
		"Estonia",
		"Ethiopia",
		"Fiji",
		"Finland",

		"France",
		"Gabon",
		"Gambia",
		"Georgia",
		"Germany",
		"Ghana",
		"Greece",
		"Grenada",
		"Guatemala",

		"Guinea",
		"Guinea-Bissau",
		"Guyana",
		"Haiti",
		"Honduras",
		"Hungary",
		"Iceland",
		"India",
		"Indonesia",

		"Iran",
		"Iraq",
		"Ireland",
		"Israel",
		"Italy",
		"Jamaica",
		"Japan",
		"Jordan",
		"Kazakhstan",

		"Kenya",
		"Kiribati",
		"North Korea",
		"South Korea",
		"Kuwait",
		"Kyrgyzstan",
		"Laos",
		"Latvia",
		"Lebanon",

		"Lesotho",
		"Liberia",
		"Libya",
		"Liechtenstein",
		"Lithuania",
		"Luxembourg",
		"Macedonia",
		"Madagascar",
		"Malawi",

		"Malaysia",
		"Maldives",
		"Mali",
		"Malta",
		"Marshall Islands",
		"Mauritania",
		"Mauritius",
		"Mexico",
		"Micronesia",

		"Moldova",
		"Monaco",
		"Mongolia",
		"Montenegro",
		"Morocco",
		"Mozambique",
		"Myanmar",
		"Namibia",
		"Nauru",

		"Nepal",
		"Netherlands",
		"New Zealand",
		"Nicaragua",
		"Niger",
		"Nigeria",
		"Norway",
		"Oman",
		"Pakistan",

		"Palau",
		"Palestine","Panama",
		"Papua New Guinea",
		"Paraguay",
		"Peru",
		"Philippines",
		"Poland",
		"Portugal",
		"Qatar",

		"Romania",
		"Russia",
		"Rwanda",
		"Saint Kitts and Nevis",
		"Saint Lucia",
		"Saint Vincent and the Grenadines",
		"Vincent and the Grenadines",
		"Samoa",
		"San Marino",
		"Sao Tome and Principe",

		"Saudi Arabia",
		"Senegal",
		"Serbia and Montenegro",
		"Seychelles",
		"Sierra Leone",
		"Singapore",
		"Slovakia",
		"Slovenia",
		"Solomon Islands",

		"Somalia",
		"South Africa",
		"Spain",
		"Sri Lanka",
		"Sudan",
		"Suriname",
		"Swaziland",
		"Sweden",
		"Switzerland",

		"Syria",
		"Taiwan",
		"Tajikistan",
		"Tanzania",
		"Thailand",
		"Togo",
		"Tonga",
		"Trinidad and Tobago",
		"Tunisia",

		"Turkey",
		"Turkmenistan",
		"Tuvalu",
		"Uganda",
		"Ukraine",
		"United Arab Emirates",
		"United Kingdom",
		"United States",
		"Uruguay",

		"Uzbekistan",
		"Vanuatu",
		"Vatican City",
		"Venezuela",
		"Vietnam","Yemen","Zambia","Zimbabwe"
	};

}
